package com.zyh.work

import scala.io.StdIn
import scala.util.control.Breaks

object Work {

  def main(args: Array[String]): Unit = {
    var ids = Array(2,2,3)
    var index = t1(ids,2)
    println(s"index = ${index}")
  }
  def t1(ids:Array[Int],id:Int): Int = {
    for(i <- 0 until ids.length if ids(i) == id) return i
    -1
  }
  // 1
  def count(days: Int) = days/7+"个星期零"+days%7+"天"
  // 2
  def test2(num: Int) = 5/9*(num-100)
  // 3
  def test3(a:Int,b:Int) = if((a+b)>=50) println("hello world")
  // 4
  def test4(a:Double,b:Double) = if(a>10.0 && b<20.0) println(a+b)
  // 5
  def test5(a:Int,b:Int) = if((a+b)%3==0 && (a+b)%5==0) println("能被整除") else println("不能被整除")
  // 6
  def test6(year:Int) = if(year%4==0 && year%100!=0 || year%400==0) println("润年") else println("不是闰年")
  // 7
  def test7(score:Double) = {
    if(score>=60 && score<=80) println("ipad")
    else if(score<=99) println("iphone7")
    else if(score==100) println("BMW")
  }
  // 8
  def test8() = {
    var count = 0
    var sum = 0
    for(i <- 1 to 100 if i % 9 == 0){
      count+=1
      sum+=i
    }
    println(s"count,sum = ${count},$sum")
  }
  // 9
//  def test9()= {
//    Breaks.breakable{
//      for (i <- 0 to 6){
//        for(j <- 6 to(0,-1)){
//          println(s"${i}+$j=${i+j}")
//          Breaks.break()
//        }
//
//      }
//    }
//  }
  // 10
  def test10() = for(i <- 0 to 100 if i % 3 ==0 ) println(i)
  // 11
  def test11() = for(i <- 40 to 200 if i % 2 ==0 ) println(s"i = ${i}")
  // 12
  def test12() = for(i <- 0 to 9;j <- 0 to 9) println(s"${i}*${j}=${i*j}")
  // 13
  def test13() = {
    Breaks.breakable{
      var count = 3
      for (i <- 1 to 3){
        println("账户")
        var username = StdIn.readLine()
        println("密码")
        var password = StdIn.readLine()
        if(verify(username, password)){
          println("success")
          Breaks.break()
        }else{
          count-=1
          println(s"还剩${count}次")
        }
        if(count<1){
          println("次数0")
        }
      }
    def verify(username:String,password:String) = if(username.equals("张无忌") && password.equals("888")) true else false
    }
  }
  def test14() = {
    var money:Double = 100000.0
    var count = 0
    Breaks.breakable{
      while(true){
        if(money>50000){
          money-=money*0.05
          count+=1
        }else{
          money-=1000
          count+=1
        }
        if(money<1000) Breaks.break()
      }
    }
    println(s"count = ${count}")
  }
  def test15(num:Int) = {
    var count = 1
    for (i <- 1 to num) count*=i
    println(s"count = ${count}")
  }
  def test16() = {
    var count = 0
    for(i <- 0 to 100 if i%3==0 && i%5!=0 ){
      count+=i
    }
    println(s"count = ${count}")
  }
  def test17() = {
    var num:Double = 10000
    for(i <- 1 to 5) num+=num*0.003
    println(s"num = ${num}")
  }
  def test18() = {
    for(i <- 100 to 999){
      var a = i/100
      var b = i%100/10
      var c = i%10
      if(((a*a*a)+(b*b*b)+(c*c*c))==i) println(s"i = ${i}")
    }
  }
  def test19() = {
    for(i <- 0 to 100/3){
      for(j <- 0 to 100/2){
        var c = 100-i-j
        if((i*3+j*2+(100-i-j)/3==100 && i+j+c==100 && c%3==0)) println(s"公,母,小 = ${i},${j},${c}")
      }
    }
  }
  def test20(num:Int) = {
    var n = 1
    for(i <- 1 until num){
      if(i==1)println("*")
      n+=2
      for(j <- 1 to n) print("*")
      println()
    }
  }
  def test21(num:Int) = {
    for(i <- 1 to num;j <- 1 to num;if i*j==num) println(s"i = ${i}")
  }
  def test22(num:Int) = {
    var sum = 0
    for(i <- 1 to num) sum+=i;
    println(s"sum = ${sum}")
  }
  def test23(num:Int) = for(i <- 1 to num) println("hello world : " + i)
  def test24(num:Int) = println(s"${num.toString.length}位数")
  def test25() = {
    var a = 0
    var b = 0
    var c = 0
    for(i <- 100 to 999){
      a=count(i/100)
      b=count(i%100/10)
      c=count(i%10)
      if(a+b+c==i) println(s"i = ${i}")
    }
    def count(num:Int) = {
      var total = 1
      for(i <- 1 to num) total*=i
      total
    }
  }
  def test26(num:Int) = {
    var count = 0
    for(i <- 1 to num if num%i==0) count+=1
    if(count>2) println("no") else println("yes")
  }
  def test27() = {

  }
  def test(ids:Array[Int],id:Int) = println(s"index = ${ids.indexOf(id)}")
}
